package com.shr.lease.web.admin.custom.converter;

import com.shr.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author Haoran Sun
 * @since 2024/06/14
 */
@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
        return Arrays.stream(ItemType.values())
                .filter(itemType -> itemType.getCode().toString().equals(source))
                .findFirst()
                .orElse(null);
    }
}
